package servlet;

import bean.Result;
import biz.BizException;
import biz.userBiz;
import com.google.gson.Gson;
import dao.QueryUserdao;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@WebServlet("/queryadd.s")
public class QueryaddServlet extends HttpServlet {
    userBiz biz = new userBiz();
    QueryUserdao dao=new QueryUserdao();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        final HttpSession session = req.getSession();
        final Object user = session.getAttribute("user");
        final Map<String, Object> map = dao.queryid((String) user);
        final Integer uid = (Integer) map.get("id");
        Result result = null;
        try {
            List<Map<String, Object>> list = new ArrayList<>();
            list = biz.queryadd(uid);
            result = new Result(1, "地址查询成功", list);
        } catch (BizException e) {
            e.printStackTrace();
        } catch (Exception e1) {
            result = new Result(0, e1.getMessage(), null);
        }
        final String json = new Gson().toJson(result);
        resp.getWriter().append(json);
    }
}
